// src/api/upload.ts
import request from './request';

// 图片上传响应类型
interface ImageUploadResponse {
  code: number;
  message: string;
  data: string; // 图片访问URL
}

// PDF上传响应类型
interface PdfUploadResponse {
  code: number;
  message: string;
  data: string; // PDF访问URL
}

/**
 * 上传图片文件
 * @param file 图片文件对象
 * @returns Promise<ImageUploadResponse>
 */
export function uploadImage(file: File): Promise<ImageUploadResponse> {
  const formData = new FormData();
  formData.append('file', file);
  
  return request({
    url: '/api/upload/image',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
}

/**
 * 上传PDF文件
 * @param file PDF文件对象
 * @returns Promise<PdfUploadResponse>
 */
export function uploadPdf(file: File): Promise<PdfUploadResponse> {
  const formData = new FormData();
  formData.append('file', file);
  
  return request({
    url: '/api/upload/pdf',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
}